const daoCommon = require('../util/daoCommon');
const commonUtils = require('../util/commonUtils');

const dao = {
    handleAddCategory: (data) => {
        let sql;
        const id = commonUtils.genUUID();
        const date = new Date();
        const createTime = date.toLocaleString();
        data.id = id;
        data.createTime = createTime;
        sql = `INSERT INTO category VALUES ($id, $title, $number,$content,$createTime,null,null,null,'0')`;
        return daoCommon.queryCommon(sql, data);
    },
    handleEditCategory: (data) => {
        let sql;
        const date = new Date();
        const updatedTime = date.toLocaleString();
        data.updatedTime = updatedTime;
        sql = `UPDATE category SET category_title=$title, category_number=$number,category_content=$content,updated_time=$updatedTime where category_id=$id`;
        return daoCommon.queryCommon(sql, data);
    },
    handleDeleteCategory: (data) => {
        let sql;
        sql = `UPDATE category SET is_delete='1' where category_id=$id`;
        return daoCommon.queryCommon(sql, data);
    },
    handleGetCategory: (data) => {
        let sql;
        sql = "select category_id as id,category_title as title,category_number as number,category_content as content from category where is_delete='0' order by category_number";
        return daoCommon.selectCommon(sql);
    },
    handleGetImgUrl: () => {
        let sql;
        sql = "select picture_url from picture where picture_type='1'";
        return daoCommon.selectCommon(sql);
    }
};
module.exports = dao;